package com.design.patterns.list.composite;

import java.util.ArrayList;
import java.util.List;

/**
 * composite 有子节点的部件，实现component具体的操作
 * @author Wangzhiwen
 */
public class University extends OrganizationComponent {

    private List<OrganizationComponent> organizationComponents = new ArrayList<>();

    public University(String name, String desc) {
        super(name, desc);
    }

    @Override
    protected void add(OrganizationComponent component) {
        organizationComponents.add(component);
    }

    @Override
    protected void remove(OrganizationComponent component) {
        organizationComponents.remove(component);
    }

    @Override
    protected List<OrganizationComponent> getChild() {
        return organizationComponents;
    }

    // composite 具体的行为
    @Override
    protected void operation() {
        System.out.println("University 节点内容 ------------- ");
        System.out.println(getName() + " " + getDesc());
        for (OrganizationComponent component : organizationComponents) {
            component.operation();
        }
    }
}
